/**
 * Copyright © 2014 Winit Corp. All rights reserved.
 * This software is proprietary to and embodies the confidential
 * technology of Winit Corp.  Possession, use, or copying
 * of this software and media is authorized only pursuant to a
 * valid written license from Winit Corp or an authorized sublicensor.
 */
package com.winit.openapi.ups.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSON;
import com.winit.common.spi.context.CommandContext;
import com.winit.openapi.controller.BaseController;
import com.winit.openapi.model.RequestMsg;
import com.winit.openapi.model.ResponseMsg;
import com.winit.ups.spi.systemrule.CarrierService;
import com.winit.ups.spi.systemrule.UpsCarrierService;
import com.winit.ups.spi.systemrule.command.CarrierQueryCommand;
import com.winit.ups.spi.systemrule.command.QueryUpsCarrierByTypeCommand;
import com.winit.ups.spi.systemrule.vo.CarrierVo;
import com.winit.ups.spi.systemrule.vo.UpsCarrierVo;

/**
 * 承运人接口
 * 
 * @version 
 * <pre>
 * Author	Version		Date		Changes
 * qianyun.yang_guest 	1.0  		2016年7月4日 	Created
 *
 * </pre>
 * @since 1.
 */
@Controller
@RequestMapping(value = "/ups/carrier")
public class UpsCarrierController extends BaseController {

    @Resource
    private CarrierService upsCarrierService;
    
    @Resource
    private UpsCarrierService upsShipperService;
    
    
    @RequestMapping(value = "/getAllCarriers")
    public String getAllCarriers(@ModelAttribute RequestMsg requestMsg, @ModelAttribute ResponseMsg responseMsg) {
        CarrierQueryCommand command = JSON.parseObject(requestMsg.getData().toString(),CarrierQueryCommand.class);
        command.setCtx(CommandContext.getContext());
        List<CarrierVo> vos = upsCarrierService.getAllCarriersByType(command);
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("carrierList", vos);
        responseMsg.setData(map);
        return SUCCESS;
    }
    
    @RequestMapping(value = "/getCarriersByType")
    public String getCarriersByType(@ModelAttribute RequestMsg requestMsg, @ModelAttribute ResponseMsg responseMsg) {
        QueryUpsCarrierByTypeCommand command = JSON.parseObject(requestMsg.getData().toString(),QueryUpsCarrierByTypeCommand.class);
        command.setCtx(CommandContext.getContext());
        List<UpsCarrierVo> vos = upsShipperService.getCarriersByType(command);
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("carrierList", vos);
        responseMsg.setData(map);
        return SUCCESS;
    }
}
